import { API } from './BaseApi'
import Utils from '../../vue2-flow/src/utils/Common'
import { Device } from "@/api/DeviceApi";

/**
 * 设备维护接口
 */
class SysDriveApi {
  /**
   * 添加设备
   * @param DriveInfo
   * @param callback
   * @returns {Promise<void>}
   * @constructor
   */
  async AddDrive (DriveInfo, callback) {
    const nd = await Device.Save(DriveInfo)
    callback(nd.Data)
  }

  /**
   * 获取所有设备
   * @param callback
   * @returns {Promise<void>}
   * @constructor
   */
  // async GetDrivelist (callback) {
  //   const list = await API.SysDeviceApi.GetDrivelist()
  //   if (Utils.IsEmpty(list)) {
  //     callback([])
  //   }
  //   callback(JSON.parse(list))
  // }

  /**
   * 根据 ID 获取设备的详情信息
   * @param Id
   * @param callback
   * @returns {Promise<void>}
   * @constructor
   */
  async GetDriveInfoById (Id, callback) {
    const info = await API.SysDeviceApi.GetDriveInfoById(Id)
    if (Utils.IsEmpty(info)) {
      callback({})
    }
    callback(JSON.parse(info))
  }

  /**
   * 根据 ID 删除设备
   * @param Id
   * @param callback
   * @returns {Promise<void>}
   * @constructor
   */
  async DeleteDevice (Id, callback) {
    const de = await Device.Delete(Id)
    callback(de)
  }

  GetConnectedClients (ServerId, Callback) {
    API.SysDeviceApi.GetConnectedClients(ServerId).then(res => {
      Callback(JSON.parse(res))
    })
  }

  async SendMessage (ServerId, ClientIndex, Message, callback) {
    const de = await Device.SendMessage(ServerId,ClientIndex,Message)
    callback(de)
  }
}

export default SysDriveApi
